﻿using CQIE.LabAssist.DataAccesss;
using CQIE.LabAssist.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace CQIE.LabAssist.Controllers
{
    /// <summary>
    /// 楼栋控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BuildingController : Controller
    {
        private readonly IBuildingService _buildingService;

        public BuildingController(IBuildingService userService)
        {
            _buildingService = userService;
        }

        #region 获取所有楼栋
        /// <summary>
        /// 获取所有楼栋
        /// </summary>
        /// <returns></returns>
        [Authorize]
        [HttpGet]
        public JsonResult getAllBuilding()
        {
            return new JsonResult(_buildingService.getAllBuilding());
        }
        #endregion

        #region 新增楼栋
       
        //public record building
        //{
        //    public int Id { get; set; }
        //    public string Name { get; set; }

        //    public int academicianId { get; set; }
        //}
        /// <summary>
        /// 新增楼栋
        /// </summary>
        /// <param name="building"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult addBuilding([FromBody] Building building)
        {          
            if ( _buildingService.addBuilding(building))
            {
                return new JsonResult("添加成功");
            }
            else
            {
                return new JsonResult("添加失败");

            }
           
        }
        #endregion

        #region 删除楼栋

        /// <summary>
        /// 删除楼栋
        /// </summary>
        /// <param name="building"></param>
        /// <returns></returns>
        [HttpDelete]
        public JsonResult deteltBuilding(int buildindId)
        {
            if (_buildingService.deteltBuilding(buildindId))
            {
                return new JsonResult("删除成功");
            }
            else
            {
                return new JsonResult("删除失败");

            }

        }
        #endregion

        #region 修改楼栋
        /// <summary>
        /// 修改楼栋
        /// </summary>
        /// <param name="building"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult updateBuilding(Building building)
        {
            if (_buildingService.updateBuilding(building))
            {
                return new JsonResult("修改成功");
            }
            else
            {
                return new JsonResult("修改失败");
            }
        }
        #endregion

    }
}
